package com.liuqi.iot.service;

import com.liuqi.iot.bean.dto.GatewayDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 网关服务封装
 *
 * @author LiuQi 2025/3/23-9:49
 * @version V1.0
 **/
@Service
public class GatewayService {
    @Autowired
    private GatewayEntityService gatewayEntityService;

    @Autowired
    private KafkaNoticeService kafkaNoticeService;

    /**
     * 发布
     *
     * @param id 网关id
     */
    public void publish(String id) {
        GatewayDTO dto = new GatewayDTO();
        dto.setId(id);
        dto.setStatus(1);
        gatewayEntityService.update(dto);
        kafkaNoticeService.restartGateway(id);
    }

    /**
     * 离线
     *
     * @param id 网关id
     */
    public void offline(String id) {
        GatewayDTO dto = new GatewayDTO();
        dto.setId(id);
        dto.setStatus(0);
        gatewayEntityService.update(dto);
        kafkaNoticeService.stopGateway(id);
    }
}
